$(function() {
        $("#s_add_follow").click(function() {
                $("#follow_btn").trigger("click")
        });
        $("#s_add_repost").click(function() {
                $("#repost_btn").trigger("click")
        });
        function a(b, c) {
                if (b == c) {
                        return "selected='selected'"
                } else {
                        return ""
                }
        }
        $("a[id^=edit_]").click(function() {
                var o = $(this);
                var d = o.attr("id");
                var j = d.split("_");
                var m = j[1];
                var n = j[2];
                if (m == 0) {
                        var f = $("#f_" + n + " td").eq(1).text();
                        var b = $("#f_" + n + " td").eq(3).text();
                        b = b.split("/");
                        var e = b[1];
                        var h = b[0];
                        var g = $("#f_" + n + " td").eq(2).find("input[name=gender_limit]").val();
                        var c = $("#f_" + n + " td").eq(2).find("input[name=fans_limit]").val();
                        var l = '<span class="left">修改推广</span> <a href="javascript:;" class="close" onclick="$(\'#' + d + "').popover('hide');\">&times;</a>";
                        var k = ["<div>", '<p style="margin-bottom:10px;">提示：出分至少3分，最多99分，要暂停/开启推广请点击状态栏下的暂停/开启按钮</p>', '<span class="fbold">出分：</span><input value="' + f + '" id="f_edit_points_' + n + '" class="span1" type="text" placeholder="请输入整数" style="padding:2px;" maxlength="3"/>', '<div class="mt10">', '<span class="fbold">性别限制：</span><select class="follow_select" id="f_edit_gender_' + n + '"><option value="0" ' + a(g, 0) + '>不限</option><option value="1" ' + a(g, 1) + '>女</option><option value="2" ' + a(g, 2) + ">男</option></select>", "</div>", '<div class="mt10">', '<span class="fbold">粉丝数限制：</span><input value="' + c + '" id="f_edit_fans_' + n + '" class="span1" type="text" style="padding:2px; width:130px;" maxlength="6"/>', "</div>", '<div class="mt10">', '<span class="fbold">最大次数：</span><input value="' + e + '" id="f_max_num_' + n + '" class="span1" type="text" style="padding:2px; width:145px;" maxlength="4"/>', "<p>(修改的最大次数必须大于当前的点击数)</p>", "</div>", '<a id="f_doedit_' + n + '" class="btn btn-primary mt10">确定</a>', "</div>"];
                        var i = k.join("");
                        o.popover({
                                trigger: "manual",
                                placement: "left",
                                title: l,
                                content: i
                        });
                        o.popover("toggle");
                        $("#f_doedit_" + n).click(function() {
                                var q = $(this);
                                var u = $.trim($("#f_edit_points_" + n).val());
                                var p = $.trim($("#f_max_num_" + n).val());
                                var t = $("#f_edit_gender_" + n).val();
                                var r = $.trim($("#f_edit_fans_" + n).val());
                                var s = /^\d{1,2}$/;
                                if (!s.test(u)) {
                                        TU.msgbox.alert(q.offset().top, "出分最多99分");
                                        return false
                                }
                                if (parseInt(u) <= 2) {
                                        TU.msgbox.alert(q.offset().top, "出分至少设置3分");
                                        return false
                                }
                                s = /^\d{1,4}$/;
                                if (!s.test(p)) {
                                        TU.msgbox.alert(q.offset().top, "最大次数请输入一到四位数字");
                                        return false
                                }
                                if (parseInt(p) != 0 && parseInt(p) <= parseInt(h)) {
                                        TU.msgbox.alert(q.offset().top, "修改的最大次数必须大于当前的点击数");
                                        return false
                                }
                                s = /^\d{1,6}$/;
                                if (!s.test(r)) {
                                        TU.msgbox.alert(q.offset().top, "限制粉丝数请输入一到六位数字");
                                        return false
                                }
                                if (r > u * FAN_POINT_SCALA) {
                                        TU.msgbox.alert(q.offset().top, "限制粉丝数不能大于设置出分的" + FAN_POINT_SCALA + "倍，您最大可设置的粉丝数为" + u * FAN_POINT_SCALA);
                                        return false
                                }
                                $.post("../welcome/updatefollowg", {
                                        tid: n,
                                        points: u,
                                        max_num: p,
                                        gender: t,
                                        fans: r
                                }, function(v) {
                                        if (v.status == 1) {
                                                TU.msgbox.success(q.offset().top, "修改成功");
                                                o.popover("hide");
                                                o.closest("tr").find("td").eq(1).text(u);
                                                o.closest("tr").find("td").eq(3).text(h + "/" + p)
                                        } else {
                                                TU.msgbox.alert(q.offset().top, v.info)
                                        }
                                }, "json")
                        })
                } else {
                        if (m == 1) {
                                var f = $("#r_" + n + " td").eq(1).text();
                                var b = $("#r_" + n + " td").eq(3).text();
                                b = b.split("/");
                                var e = b[1];
                                var h = b[0];
                                var c = $("#r_" + n + " td").eq(2).find("input[name=rfans_limit]").val();
                                var g = $("#r_" + n + " td").eq(2).find("input[name=gender_limit]").val();
                                var l = '<span class="left">修改推广</span> <a href="javascript:;" class="close" onclick="$(\'#' + d + "').popover('hide');\">&times;</a>";
                                var k = ["<div>", '<p style="margin-bottom:10px;">提示：出分至少3分，最多99分，要暂停/开启推广请点击状态栏下的暂停/开启按钮</p>', '<span class="fbold">出分：</span><input value="' + f + '" id="r_edit_points_' + n + '" class="span1" type="text" placeholder="请输入整数" style="padding:2px;" maxlength="3"/>','<div class="mt10">', '<span class="fbold">性别限制：</span><select class="follow_select" id="r_edit_gender_' + n + '"><option value="0" ' + a(g, 0) + '>不限</option><option value="1" ' + a(g, 1) + '>女</option><option value="2" ' + a(g, 2) + ">男</option></select>", "</div>", '<div class="mt10">', '<span class="fbold">粉丝数限制：</span><input value="' + c + '" id="r_edit_fans_' + n + '" class="span1" type="text" style="padding:2px; width:130px;" maxlength="6"/>', "</div>", '<div class="mt10">', '<span class="fbold">最大次数：</span><input value="' + e + '" id="r_max_num_' + n + '" class="span1" type="text" style="padding:2px; width:145px;" maxlength="4"/>', "<p>(修改的最大次数必须大于当前的点击数)</p>", "</div>", '<a id="r_doedit_' + n + '" class="btn btn-primary mt10">确定</a>', "</div>"];
                                var i = k.join("");
                                o.popover({
                                        trigger: "manual",
                                        placement: "left",
                                        title: l,
                                        content: i
                                });
                                o.popover("toggle");
                                $("#r_doedit_" + n).click(function() {
                                        var q = $(this);
                                        var t = $.trim($("#r_edit_points_" + n).val());
                                        var p = $.trim($("#r_max_num_" + n).val());
                                        var r = $.trim($("#r_edit_fans_" + n).val());
                                        var l = $("#r_edit_gender_" + n).val();
                                        var s = /^\d{1,2}$/;
                                        if (!s.test(t)) {
                                                TU.msgbox.alert(q.offset().top, "出分最多99分");
                                                return false
                                        }
                                        if (parseInt(t) <= 2) {
                                                TU.msgbox.alert(q.offset().top, "出分至少设置3分");
                                                return false
                                        }
                                        s = /^\d{1,4}$/;
                                        if (!s.test(p)) {
                                                TU.msgbox.alert(q.offset().top, "最大次数请输入一到四位数字");
                                                return false
                                        }
                                        s = /^\d{1,6}$/;
                                        if (!s.test(r)) {
                                                TU.msgbox.alert(q.offset().top, "限制粉丝数请输入一到六位数字");
                                                return false
                                        }
                                        if (r > t * FAN_POINT_SCALA) {
                                                TU.msgbox.alert(q.offset().top, "限制粉丝数不能大于设置出分的" + FAN_POINT_SCALA + "倍，您最大可设置的粉丝数为" + t * FAN_POINT_SCALA);
                                                return false
                                        }
                                        if (parseInt(p) != 0 && parseInt(p) <= parseInt(h)) {
                                                TU.msgbox.alert(q.offset().top, "修改的最大次数必须大于当前的点击数");
                                                return false
                                        }
                                        $.post("../welcome/updaterepostg", {
                                                tid: n,
                                                points: t,
                                                max_num: p,
                                                fans: r,
                                                gender: l
                                        }, function(u) {
                                                if (u.status == 1) {
                                                        TU.msgbox.success(q.offset().top, "修改成功");
                                                        o.popover("hide");
                                                        o.closest("tr").find("td").eq(1).text(t);
                                                        o.closest("tr").find("td").eq(3).text(h + "/" + p)
                                                } else {
                                                        TU.msgbox.alert(q.offset().top, u.info)
                                                }
                                        }, "json")
                                })
                        }
                }
        });
        $("a[id^=del_]").click(function() {
                var b = $(this);
                var f = b.attr("id");
                var e = f.split("_");
                var d = e[1];
                var c = e[2];
                TU.msgbox.confirm("确定要删除该条推广吗？", function() {
                        $.post("../welcome/deleteg", {
                                tid: c,
                                type: d
                        }, function(g) {
                                if (g.status == 1) {
                                        TU.msgbox.success(b.offset().top, "删除成功");
                                        b.closest("tr").fadeOut()
                                } else {
                                        TU.msgbox.alert(b.offset().top, g.info)
                                }
                        }, "json")
                })
        });
        $("a[id^=play_]").click(function() {
                var c = $(this);
                var f = c.attr("id");
                var e = f.split("_");
                var d = e[1];
                var b = e[2];
                $.post("../welcome/setactive", {
                        active: 1,
                        tid: b,
                        type: d
                }, function(g) {
                        if (g.status == 1) {
                                TU.msgbox.success(c.offset().top, "开启推广成功");
                                c.hide();
                                $("#stop_" + d + "_" + b).show()
                        } else {
                                TU.msgbox.alert(c.offset().top, g.info)
                        }
                }, "json")
        });
        $("a[id^=stop_]").click(function() {
                var c = $(this);
                var f = c.attr("id");
                var e = f.split("_");
                var d = e[1];
                var b = e[2];
                $.post("../welcome/setactive", {
                        active: 0,
                        tid: b,
                        type: d
                }, function(g) {
                        if (g.status == 1) {
                                TU.msgbox.success(c.offset().top, "暂停推广成功");
                                c.hide();
                                $("#play_" + d + "_" + b).show()
                        } else {
                                TU.msgbox.alert(c.offset().top, g.info)
                        }
                }, "json")
        })
});